home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 2.8 KB | 79 lines | [TEXT/GEOL] |
- Item 3592180 16-Aug-89 19:15
-
- From: ALGER Alger, Jeff,VCA
-
- To: AU0008 Kopfwerk EDV SW Entwicklung
-
- cc: MACAPP.TECH$ MACAPP Tech
-
- Sub: Response to ?Memory Management
-
- Tommi,
-
- Maybe someone else knows of a better way to list the total sizes of objects
- from the debugger, but if you are willing to roll up your sleeves a bit, all of
- the information is readily available in UInspector. The method
-
- FUNCTION TInspector.GetObjectList(classId: ObjClassID): TObjectList;
-
- returns a TObjectList, which is a subclass of TList containing all objects of
- the given class. In UObject you will find the global procedure
-
- PROCEDURE EachClassDo(PROCEDURE DoToClass(theClass: ObjClassID));
-
- which iterates over all classes. Finally, TObject now has a method which
- returns the actual size currently occupied by an object:
-
- FUNCTION TObject.GetInstanceSize: INTEGER;
-
- In theory, (I haven't actually tried it) one can chain all of this together to
- report the number and collective size of objects by class. The only problem is
- that TInspector and its associated classes are declared privately in
- UInspector, so you have to modify MacApp source (in UInspector) to do this.
- ugh.
-
- The following, put into UInspector.inc1.p, shows how:
-
- PROCEDURE EachObjectForClass (theClass: ObjClassID;
- PROCEDURE DoToObject (anObject: TObject));
- VAR theClassList: TObjectList;
- BEGIN
- IF pInspector <> NIL THEN
- BEGIN
- theClassList := pInspector.GetObjectList (theClass);
- IF theClassList <> NIL THEN
- theClassList.Each (DoToObject);
- END;
- END;
-
- FUNCTION ComputeSizeForClass (theClass: ObjClassID;
- VAR howManyAreThere: LONGINT): LONGINT;
- VAR totalSize: LONGINT;
- PROCEDURE DoToObject (theObject: TObject);
- BEGIN
- totalSize := totalSize + theObject.GetInstanceSize;
- howManyAreThere := howManyAreThere + 1;
- END;
- BEGIN
- totalSize := 0;
- howManyAreThere := 0;
- EachObjectForClass (theClass, DoToObject);
- ComputeSizeForClass := totalSize;
- END;
-
- Use EachClassDo to iterate over all classes, calling ComputeSizeForClass for
- each one. Again, I haven't tested this beyond making sure it compiles; it's
- just an idea I've had kicking around for awhile. If anyone tries it out, let
- me know how it works.
-
- It seems to me that the object lists by class could and should be published in
- the interface to UInspector for uses such as this, but perhaps there are
- problems with that of which I am unaware. As it is, they are tied to views of
- the inspector window: one view per class.
-
- Hope this helps.
-
- Jeff Alger
- Peat Marwick Main & Co.
-
-